package com.aoxin.controller.attendance;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.attendance.SlfClassRecord;
import com.aoxin.model.dto.ClassRecordDto;
import com.aoxin.service.inter.attendance.ClassRecordService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.ThreadLocalUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.enumerate.UserType;
import com.aoxin.util.log.LogInfo;

/**
 * 上课记录Controller
 * 
 * @author Melody
 * @date 2018年3月28日 下午3:33:54
 */
@Controller
@ResponseBody
@RequestMapping("/web/classRecord")
public class ClassRecordController {

	@Autowired
	private ClassRecordService classRecordService;

	/**
	 * 添加上课记录
	 * 
	 * @param classRecord
	 *            上课记录
	 */
	@RequestMapping("/insertClassRecord")
	public AjaxRes insertClassRecord(SlfClassRecord classRecord, AjaxRes ajaxRes) {
		try {
			this.classRecordService.insertClassRecord(classRecord);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 批量删除上课记录
	 * 
	 * @param classRecordIds
	 *            上课记录ID集合
	 */
	@RequestMapping("/deleteClassRecords")
	public AjaxRes deleteClassRecords(@RequestParam("classRecordIds") List<Integer> classRecordIds, AjaxRes ajaxRes) {
		try {
			this.classRecordService.deleteClassRecords(classRecordIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 修改上课记录
	 * 
	 * @param classRecord
	 *            上课记录
	 */
	@RequestMapping("/updateClassRecord")
	public AjaxRes updateClassRecord(SlfClassRecord classRecord, AjaxRes ajaxRes) {
		try {
			this.classRecordService.updateClassRecord(classRecord);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询上课记录
	 * 
	 * @param classRecordId
	 *            上课记录ID
	 */
	@RequestMapping("/getClassRecord")
	public AjaxRes getClassRecord(@RequestParam("classRecordId") Integer classRecordId, AjaxRes ajaxRes) {
		try {
			SlfClassRecord slfClassRecord = this.classRecordService.getClassRecord(classRecordId);
			ajaxRes.setSucceed(slfClassRecord, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询上课记录
	 * 
	 * @param classRecordId
	 *            上课记录ID
	 */
	@RequestMapping("/getClassRecordList")
	public AjaxRes getClassRecordList(@RequestParam Map<String, Object> map, AjaxRes ajaxRes) {
		try {
			List<SlfClassRecord> slfClassRecord = this.classRecordService.getClassRecordList(map);
			ajaxRes.setSucceed(slfClassRecord, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询用户考勤记录
	 * 
	 */
	@RequestMapping("/getClassRecordListByUser")
	@LogInfo(content = "查询考勤记录", operateType = OperateType.QUERY, userType = UserType.USER)
	public AjaxRes getClassRecordListByUser(AjaxRes ajaxRes) {
		try {
			List<ClassRecordDto> classRecordDtos = this.classRecordService.getClassRecordListByUser(ThreadLocalUtil.getUser().getUserId());
			ajaxRes.setSucceed(classRecordDtos, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
